package benny.ApkposStore.Adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import benny.ApkposStore.R;
import benny.ApkposStore.model.Make_tbl;
import benny.ApkposStore.utils.Rotate3dView;

public class cookAdapter extends BaseAdapter {

	private Context context;
	private List<Make_tbl> list;
	private LayoutInflater mInflater;
	//private TextPaint tp = null;

	public cookAdapter(Context context, List<Make_tbl> list) {
		this.context = context;
		this.list = list;
		mInflater = LayoutInflater.from(this.context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null)
			return list.size();
		else
			return 0;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if (list != null)
			return list.get(position);
		else
			return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressWarnings("unused")
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Cooklistholder cookselectholder = null;

		if (cookselectholder == null) {
		cookselectholder = new Cooklistholder();	
		convertView = mInflater.inflate(R.layout.cookitem, null);
		cookselectholder.cookitem1 = (TextView) convertView
				.findViewById(R.id.cookitem1);
		cookselectholder.cookitem2 = (TextView) convertView
				.findViewById(R.id.cookitem2);
		cookselectholder.cookitem3 = (TextView) convertView
				.findViewById(R.id.cookitem3);
		cookselectholder.cookitem4 = (Rotate3dView) convertView
				.findViewById(R.id.cookitem4);
		cookselectholder.cookitem5 = (Rotate3dView) convertView
				.findViewById(R.id.cookitem5);
		cookselectholder.cookitem4.setParentWidth(35);
		cookselectholder.cookitem4.setParentHeight(23);
		cookselectholder.cookitem4.setRotateImage(R.drawable.del2,R.drawable.del2);
		
		convertView.setTag(cookselectholder);
		}
		else {
			cookselectholder = (Cooklistholder)convertView.getTag();	
		}
//		addListener(convertView,position);
		cookselectholder.cookitem1.setText(list.get(position).getCook_name());
		cookselectholder.danw=list.get(position).getCook_unit();
		cookselectholder.mingc=list.get(position).getCook_name();
		cookselectholder.position=position;
		if (!cookselectholder.danw.equals("")) {
			cookselectholder.cookitem3.setText("/"+cookselectholder.danw);	
		}else {
			cookselectholder.cookitem3.setText("");	
		}
		
		cookselectholder.pric = (float) (list.get(position).getCook_price()*0.01);
		if (cookselectholder.pric>0) {
			cookselectholder.cookitem2.setText(cookselectholder.pric+"元");	
		}
		else {
			cookselectholder.cookitem2.setText("");	
		}
		
			cookselectholder.cookitem4.setVisibility(View.INVISIBLE);
			cookselectholder.cookitem5.setParentWidth(35);
			cookselectholder.cookitem5.setParentHeight(23);
			cookselectholder.cookitem5.setRotateImage(R.drawable.del2,R.drawable.del2);
	
		
		return convertView;
	}

/*	public void addListener(View convertView,int arg) {
		final int arg2=arg;
		((Rotate3dView)convertView.findViewById(R.id.cookitem5)).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {
						Toast.makeText(DishordersActivity.Activitythis, "点击了第"+arg2+"项",
								Toast.LENGTH_SHORT).show();
					
					}
				});
		((Rotate3dView)convertView.findViewById(R.id.cookitem4)).setOnClickListener(
				new View.OnClickListener() {

					public void onClick(View v) {
						if (DishordersActivity.dishcookwin != null) {
							DishordersActivity.dishcookwin.dismiss();
						}	
						
					}
				});
		
	}*/

	public final class Cooklistholder {
		public TextView cookitem1;
		public TextView cookitem2;
		public TextView cookitem3;
		public Rotate3dView  cookitem4;
		public Rotate3dView  cookitem5;
		public float  pric;
		public String  danw;
		public String  mingc;
		public  int  position;

	}

	
}